package com.anxin.act.utils;

import com.alibaba.fastjson.JSONObject;
import com.anxin.common.utils.spring.SpringUtils;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.repository.Model;
import org.activiti.engine.repository.ProcessDefinition;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: liuxiangyu
 * @date: 2020/7/28 13:47
 */
public class ActModelUtils {
    private static RepositoryService repositoryService = SpringUtils.getBean(RepositoryService.class);
    private static ProcessEngine processEngine = SpringUtils.getBean(ProcessEngine.class);

    /**
     * 根据模型ID获取模型
     * @param modeId
     * @return
     */
    public static Model getModel(String modeId){
        Model model = repositoryService.getModel(modeId);
        return model;
    }

    /**
     * 根据模型ID获取模型的 MetaInfo
     * @param modelId
     * @return
     */
    public static JSONObject getModelMetaInfo(String modelId,String deploymentId){
        Model model = ActModelUtils.getModel(modelId);
        if (model == null){
            model = repositoryService.createModelQuery().deploymentId(deploymentId).latestVersion().singleResult();
        }
        return JSONObject.parseObject(model.getMetaInfo());
    }

}
